package com.nahan.secondapplication.navigation;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.nahan.secondapplication.R;
import com.zaaach.transformerslayout.TransformersLayout;
import com.zaaach.transformerslayout.holder.Holder;
import com.zaaach.transformerslayout.holder.TransformersHolderCreator;
import com.zaaach.transformerslayout.listener.OnTransformersItemClickListener;

import java.util.List;

public class NavigationActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation);

        final List<Nav> navList = DataFactory.loadData();
        TransformersLayout<Nav> transformersLayout=findViewById(R.id.tfl);
        transformersLayout.addOnTransformersItemClickListener(new OnTransformersItemClickListener() {
                    @Override
                    public void onItemClick(int position) {
                        Toast.makeText(getApplication(), "点击：" + transformersLayout.getDataList().get(position).getText(), Toast.LENGTH_SHORT).show();
                    }
                })
                .load(navList, new TransformersHolderCreator<Nav>() {
                    @Override
                    public Holder<Nav> createHolder(View itemView) {
                        return new NavAdapterViewHolder(itemView);
                    }

                    @Override
                    public int getLayoutId() {
                        return R.layout.item_nav_list;
                    }
                });
    }
}
